home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / CDSOUND.ZIP / SOURCE.ZIP / SOUNDOFF.C < prev    next >
C/C++ Source or Header  |  1993-07-24  |  23KB  |  646 lines

  1. /***************************************************************************/
  2. /*                              CD SOUND OFF                               */
  3. /***************************************************************************/
  4. /*
  5.  
  6.     CD SoundOff is an audio CD player that is provided for your enjoyment.  
  7. If you like CD SoundOff, feel free to show me by helping with the 
  8. development costs.  Any and all donations will be greatly appreciated.
  9.  
  10.     CD SoundOff is provided as is with the C source code.  This software was 
  11. developed using the Microsoft Windows 3.1 SDK and Microsoft C 7.0.  Feel free 
  12. to add your own enhancements to CD SoundOff and please send me a copy
  13. so that I can keep up with all of the new and exciting CD bells and 
  14. whistles.  
  15.  
  16.                               NickleWare
  17.                               P.O. Box 393
  18.                               Orem, UT. 84059
  19.  
  20.  
  21.  
  22. NickleWare 
  23. CompuServe: 72730,1002
  24. Copyright (C) 93 Bradley Nicholes 
  25.  
  26. This documentation must accompany the CD SoundOff software. 
  27.  
  28. NickleWare or Bradley Nicholes shall not be liable for any damages, whether 
  29. direct, indirect, special or consequential arising from the use or failure 
  30. of this program to operate in the manner desired by the user.
  31.  
  32. */
  33.  
  34. /***************************************************************************/
  35. /*                      I N C L U D E   F I L E S                          */
  36. /***************************************************************************/
  37.  
  38. #define NOGDICAPMASKS
  39. #define NOVIRTUALKEYCODES
  40. #define NONCMESSAGES
  41. #define NODRAWFRAME
  42. #define NOKEYSTATE
  43. #define NORASTEROPS
  44.  
  45.  
  46. #include <WINDOWS.H>
  47. #include <mmsystem.h>
  48. #include "soundoff.h"
  49. #include <stdlib.h>
  50. #include <string.h>
  51.  
  52. /***************************************************************************/
  53. /*      T H E   P R O G R A M ' S   G L O B A L   V A R I A B L E S        */
  54. /***************************************************************************/
  55.  
  56. HINSTANCE hInst;
  57.  
  58. /***************************************************************************/
  59. /*                           FORWARD REFERENCES                            */
  60. /***************************************************************************/
  61.  
  62. BOOL CALLBACK SoundOffDlgProc (HWND, UINT, WPARAM, LPARAM);
  63. BOOL CALLBACK AboutboxWindowProc (HWND, UINT, WPARAM, LPARAM);
  64.  
  65. /***************************************************************************/
  66. /*                       M A I N   P R O G R A M                           */
  67. /***************************************************************************/
  68.  
  69.  
  70. int FAR PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  71. HANDLE hInstance, hPrevInstance;
  72. LPSTR  lpszCmdLine;                       /*  Length of the command line.  */
  73. int    cmdShow;                           /*  Iconic or Tiled when start.  */
  74. {
  75.  
  76.    FARPROC  lpprocSoundOff;      
  77.    HWND  hwndDlg;
  78.    MSG   msg;
  79.  
  80.    hInst = hInstance;
  81.  
  82.    // Create the main dialog window as a modeless dialog.
  83.    lpprocSoundOff = (FARPROC)MakeProcInstance( SoundOffDlgProc, hInstance);
  84.    hwndDlg = CreateDialog (hInstance, "SoundOffDlg", GetDesktopWindow(), 
  85.       lpprocSoundOff);
  86.  
  87.    // If the dialog was created correctly then contine to the main message
  88.    //  loop.  Otherwise exit the program.
  89.    if (hwndDlg == 0)
  90.       return 1;
  91.  
  92.    while (GetMessage(&msg, NULL, 0, 0))          /*  The main loop:         */
  93.    {                                             /*  (terminated by a QUIT) */
  94.       if (!IsDialogMessage(hwndDlg, &msg))
  95.       {
  96.          TranslateMessage(&msg);              /*  Have Windows translate */
  97.          DispatchMessage(&msg);               /*  Have Windows give message */
  98.       }                                       /*  to the window proc.    */
  99.    }
  100.  
  101.    // Destroy the dialog and exit the program.
  102.    DestroyWindow (hwndDlg);
  103.    FreeProcInstance ( lpprocSoundOff);
  104.    return(0);
  105. }
  106.  
  107. /***************************************************************************/
  108. /*    T H E   A B O U T   B O X   H A N D L I N G   P R O C E D U R E      */
  109. /***************************************************************************/
  110.  
  111. /*   This is the window procedure for the main CD SoundOff control panel. */
  112.  
  113.  
  114. BOOL CALLBACK SoundOffDlgProc (HWND hDlg, UINT message, WPARAM wParam, 
  115.    LPARAM lParam)
  116. {
  117.  
  118.    DRAWITEMSTRUCT FAR *pDrawItem;   // Passed in from the WM_DRAWITEM message.
  119.    HICON    hIcon;                  // Button Icon.
  120.    char     szBuffer[128];          // CD Audio command buffer.
  121.    char     szReturn[128];          // CD Audio return buffer.
  122.    static BOOL bContinuous = FALSE; // Auto-Repeat flag.
  123.    static BOOL bPlay = FALSE;       // CD Audio currently playing flag.
  124.    static BOOL bPause = FALSE;      // CD Audio currently paused flag.
  125.    static WORD wTracks;             // Total number of tracks.
  126.    static WORD wCurrTrack;          // Currently playing track.
  127.    static HICON hTrackIcon;         // Track icon.
  128.    HICON    hOldIcon;               // Previous track icon.
  129.    PAINTSTRUCT ps;                  // Paint structure.
  130.    RECT rc;                         // Window rectangle structure.
  131.    HMENU hSysMenu;                  // System menu.
  132.    FARPROC  lpprocAbout;            // About dialog proc.
  133.  
  134.    switch (message ) {
  135.  
  136.       case WM_INITDIALOG:
  137.  
  138.          // Open the cdaudio device to query the current status.
  139.          mciSendString("open cdaudio", NULL, 0, hDlg);
  140.  
  141.          // Set the cdaudio device time format.
  142.          mciSendString("set cdaudio time format tmsf", NULL, 0, hDlg);
  143.  
  144.          // Query the current state of the device.
  145.          mciSendString("status cdaudio mode", szReturn, sizeof(szReturn), 
  146.             hDlg);
  147.  
  148.          // If the cdaudio device is playing then initiallize the status
  149.          //  to the current state.
  150.          if (_stricmp (szReturn, "playing") == 0) {
  151.  
  152.             bPlay = TRUE;
  153.  
  154.             // Tell the device to notify the dialog of any events.
  155.             mciSendString("play cdaudio notify", NULL, 0, hDlg);
  156.  
  157.             // Start the status polling timer.
  158.             SetTimer(hDlg, CD_TIMER, 500, NULL);
  159.          }
  160.  
  161.          // If the cdaudio device is paused then initialize the status to
  162.          //  the current state.
  163.          if (_stricmp (szReturn, "paused") == 0) {
  164.  
  165.             bPause = TRUE;
  166.          }
  167.  
  168.          // Load and display the default track indicator icon.
  169.          hTrackIcon = LoadIcon (hInst, "NONE");
  170.  
  171.          // Add the control panel commands to the system menu.
  172.          hSysMenu = GetSystemMenu (hDlg, FALSE);
  173.  
  174.          AppendMenu (hSysMenu, MF_SEPARATOR, 0, NULL);
  175.          AppendMenu (hSysMenu, MF_STRING, IDB_PREVIOUS, "Pre&vious");
  176.          AppendMenu (hSysMenu, MF_STRING, IDB_PLAY, "&Play");
  177.          AppendMenu (hSysMenu, MF_STRING, IDB_PAUSE, "P&ause");
  178.          AppendMenu (hSysMenu, MF_STRING, IDB_STOP, "S&top");
  179.          AppendMenu (hSysMenu, MF_STRING, IDB_NEXT, "&Next");
  180.          AppendMenu (hSysMenu, MF_STRING, IDB_CONTINUOUS, "A&uto-Repeat");
  181.          AppendMenu (hSysMenu, MF_SEPARATOR, 0, NULL);
  182.          AppendMenu (hSysMenu, MF_STRING, IDM_ABOUT, "About!");
  183.  
  184.          return TRUE;
  185.  
  186.       case WM_TIMER:
  187.  
  188.          // Query the cdaudio device for the current track.
  189.          mciSendString("status cdaudio current track", szReturn, 
  190.             sizeof(szReturn), hDlg);
  191.  
  192.          // If the current track has changed then update the display.
  193.          if (wCurrTrack != (WORD)atoi(szReturn)) {
  194.          
  195.             wCurrTrack = atoi(szReturn);
  196.  
  197.             // Load and display the new track display icon.
  198.             switch (wCurrTrack) {
  199.  
  200.                case 0:
  201.                   hTrackIcon = LoadIcon (hInst, "NONE");
  202.                   break;
  203.                case 1:
  204.                   hTrackIcon = LoadIcon (hInst, "ONE");
  205.                   break;
  206.                case 2:
  207.                   hTrackIcon = LoadIcon (hInst, "TWO");
  208.                   break;
  209.                case 3:
  210.                   hTrackIcon = LoadIcon (hInst, "THREE");
  211.                   break;
  212.